|
| 1 | +from Multiplayer import * |
| 2 | +from Singleplayer import * |
| 3 | +from Tkinter import* |
| 4 | +import pygame,sys |
| 5 | +from checks import * |
| 6 | +from ships import * |
| 7 | +import pygame,sys |
| 8 | +import random |
| 9 | +import Tkinter |
| 10 | +import tkMessageBox |
| 11 | +from pygame.locals import* |
| 12 | + |
| 13 | + # ******************************************FUNCTION FOR PLAYER V/S PLAYER ************************************************************************* |
| 14 | + |
| 15 | + |
| 16 | +def player_player(): |
| 17 | + window.withdraw() |
| 18 | + if multi() == 1: |
| 19 | + window.deiconify() |
| 20 | + # ****************************************FUNCTION FOR PLAYER V/S COMPUTER ************************************************************************* |
| 21 | + |
| 22 | + |
| 23 | +def player_computer(): |
| 24 | + window.withdraw() |
| 25 | + if single() == 1: |
| 26 | + window.deiconify() |
| 27 | + |
| 28 | + # ******************************************FUNCTIONS FOR MAIN DISPLAY ************************************************************************* |
| 29 | + |
| 30 | + |
| 31 | +def Rules_page(): # functon to display the rules page |
| 32 | + |
| 33 | + p_v_p.place_forget() |
| 34 | + p_v_s.place_forget() |
| 35 | + rules_button.place_forget() |
| 36 | + window.configure(background="moccasin") |
| 37 | + Back_button.place(x=450,y=600) |
| 38 | + Rules_label.place(x=300,y=30) |
| 39 | +def Home_back(): # functon to bring back the home page from rules pages |
| 40 | + Back_button.place_forget() |
| 41 | + Rules_label.place_forget() |
| 42 | + p_v_p.place(x=420,y=400) |
| 43 | + p_v_s.place(x=420,y=500) |
| 44 | + img.grid(row=0,column=90,padx=0,pady=0) |
| 45 | + rules_button.place(x=420,y=600) |
| 46 | + pic.place(x=350,y=30) |
| 47 | + |
| 48 | +def Home_Page(): #functon to display the home page |
| 49 | + start.place_forget() |
| 50 | + lbl.place_forget() |
| 51 | + p_v_p.place(x=420,y=400) |
| 52 | + p_v_s.place(x=420,y=500) |
| 53 | + rules_button.place(x=420,y=600) |
| 54 | + |
| 55 | + # opening Tkinter window |
| 56 | + |
| 57 | +window=Tk() |
| 58 | +window.title("Battleship") |
| 59 | +window.geometry("1020x1000") |
| 60 | + |
| 61 | + # setting the background |
| 62 | + |
| 63 | +logo=PhotoImage(file="background.png") |
| 64 | +img=Label(window,image=logo) |
| 65 | +img.grid(row=0,column=90) |
| 66 | +ship_img=PhotoImage(file="Photo.png") |
| 67 | +pic=Label(window,image=ship_img) |
| 68 | +pic.place(x=350,y=30) |
| 69 | + |
| 70 | + # creating neccessary buttons |
| 71 | + |
| 72 | +p_v_p=Button(window,text="PLAYER V/S PLAYER",command=player_player,bg="firebrick1",padx=10,pady=20) |
| 73 | +p_v_s=Button(window,text="PLAYER V/S COMPUTER",command=player_computer,bg="firebrick1",padx=10,pady=20) |
| 74 | +rules_button=Button(window,text="Rules",command=Rules_page,bg="firebrick1",padx=40,pady=20) |
| 75 | +Back_button=Button(window,text="Back",command=Home_back,bg="firebrick1",padx=40,pady=20) |
| 76 | + |
| 77 | + # creating label to display rules in rules page |
| 78 | + |
| 79 | +Rules_label=Label(window,text="RULES:\n\nPlayers v/s Players:Each player places\nthe 5 ships somewhere on their board.The ships\ncan only be placed vertically\nor horizontally consecutively.Diagonal placement is not\nallowed.Ships may not overlap each other\n.No ships may be placed on another ship.Player's\ntake turns guessing by selecting random\npositions on the grid.The opponent responds with\nhitor miss as appropriate.A miss recorded by any player\nshifts the hitting chance to his opponent\n.When all of the squares that\nyour ships occupies have been hit,the ship will be sunk\n.Once if the player tries to makeout all the ships of\n opponentsthen he is declared as a winner\n.Player v/s Computer:\nHere compute randomly places five ships\n horizontally or vertically in a grid and player\nmust try to guess the expected positions\nof ships.Player must guess all the ships within a\nconstraint of 50 moves.If he does so he\nis declared winner,other wise loser.",font=1000,bg="cyan",padx=10,pady=40,relief=RAISED) |
| 80 | +lbl=Label(window,text="Enjoy the Experience of the Battleship",bg="cornflower blue",fg="blue",font=1000,relief=RAISED,padx=30,pady=30,justify=CENTER) |
| 81 | +lbl.place(x=315,y=420) |
| 82 | +start=Button(window,text="Start the Game",command=Home_Page,bg="springgreen2",padx=40,pady=20) |
| 83 | +start.place(x=400,y=550) |
| 84 | +window.mainloop() |
| 85 | + |
| 86 | + |
| 87 | + # **************************************************************** THE END ************************************************************************* |
| 88 | + |
| 89 | + |
| 90 | + |
0 commit comments