请参阅链接网页中的代码:https://msdn.microsoft.com/en-us/library/system.servicemodel.description.clientcredentials.username(v=vs.110).aspx以及以下示例代码:
import pygame
from pygame.locals import *
import random
import sys
pygame.init()
FPS = 30
fpsClock = pygame.time.Clock()
WIN_WIDTH = 680 #width of window
WIN_HEIGHT = 500 #height of window
DISPLAY = (WIN_WIDTH, WIN_HEIGHT) #variable for screen display
DEPTH = 32 #standard
FLAGS = 0 #standard
BLACK = (0, 0, 0) #black
RED = (255, 0, 0) #red
GOLD = (255, 215, 0)
LOL = (14, 18, 194)
screen = pygame.display.set_mode(DISPLAY, FLAGS, DEPTH)
pygame.display.set_caption('Snaek')
snake_parts = [1]
Score = 0
speed = 10
snakex = 125
snakey = 70
size = 20
# --- classes ---
class Snake(pygame.Rect):
def __init__(self, x, y, screen, size, colour):
pygame.Rect.__init__(self, x, y, size, 20)
self.screen = screen
self.colour = colour
self.x = x
self.y = y
def draw(self, screen):
pygame.draw.rect(self.screen, self.colour, self)
def coordinates(self):
return self.x, self.y
class Food(pygame.Rect):
def __init__(self, x, y, screen):
pygame.Rect.__init__(self, x, y, 20, 20)
self.screen = screen
def draw(self, screen):
pygame.draw.rect(self.screen, GOLD, self)
class Barrier(pygame.Rect):
def __init__(self, x, y, screen):
pygame.Rect.__init__(self, x, y, 40, 20)
self.screen = screen
def draw(self, screen):
pygame.draw.rect(self.screen, LOL, self)
# --- functions ---
def get_food_pos(WIN_WIDTH, WIN_HEIGHT):
WIN_WIDTH = random.randint(100, WIN_WIDTH-150)
WIN_HEIGHT = random.randint(100, WIN_HEIGHT-150)
return WIN_WIDTH, WIN_HEIGHT
eaten = True
pressed_right = True
pressed_left = False
pressed_up = False
pressed_down = False
pygame.key.set_repeat(10,10)
level = [
"PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP",
"P P",
"P P",
"P P",
"P P",
"P P",
"P P",
"P P",
"P P",
"P P",
"P P",
"P P",
"P P",
"P P",
"P P",
"P P",
"P P",
"P P",
"P P",
"P P",
"P P",
"P P",
"P P",
"P P",
"PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP",
]
while True:
screen.fill(BLACK)
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
elif event.type == pygame.KEYDOWN: # check for key presses
if event.key == pygame.K_LEFT:
if pressed_right:
pressed_right = True# left arrow turns left
else:
pressed_left = True
pressed_right = False
pressed_up = False
pressed_down = False
elif event.key == pygame.K_RIGHT:
if pressed_left:
pressed_left = True# right arrow turns right
else:
pressed_right = True
pressed_left = False
pressed_up = False
pressed_down = False
elif event.key == pygame.K_UP:
if pressed_down:# up arrow goes up
pressed_down = True
else:
pressed_up = True
pressed_right = False
pressed_left = False
pressed_down = False
elif event.key == pygame.K_DOWN:
if pressed_up:
pressed_up = False
else:
pressed_down = True
pressed_right = False
pressed_up = False
pressed_left = False
x = snakex
y = snakey
if pressed_left:
snakex -= speed
elif pressed_right:
snakex += speed
elif pressed_up:
snakey -= speed
elif pressed_down:
snakey += speed
snake_parts[0] = Snake(snakex, snakey, screen, int(size), RED)
snake_parts[0].draw(screen)
if eaten:
foodx, foody = get_food_pos(WIN_WIDTH, WIN_HEIGHT)
eaten = False
my_food = Food(foodx, foody, screen)
my_food.draw(screen)
if snake_parts[0].colliderect(my_food):
eaten = True
screen.fill(BLACK)
a_snake = Snake(snakex, snakey, screen, int(size), RED)
snake_parts.append(a_snake)
for i in range(1, len(snake_parts)):
tempx, tempy = snake_parts[i].coordinates()
snake_parts[i] = Snake(x, y, screen, int(size), RED)
if snake_parts[0].colliderect(snake_parts[i]):
print("Self collision")
snake_parts[i].draw(screen)
x, y = tempx, tempy
platform_x = 0
platform_y = 0
for row in level:
for col in row:
if col == "P":
col = Barrier(platform_x, platform_y, screen)
col.draw(screen)
if snake_parts[0].colliderect(col):
print("Barrier collision")
platform_x += 15
platform_y += 20
platform_x = 0
pygame.display.update()
fpsClock.tick(FPS)
如果我想使用Windows身份验证,请使用:public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
ServiceReference1.Service1Client s1 = new ServiceReference1.Service1Client();
s1.ClientCredentials.UserName.UserName = "TestUser";
s1.ClientCredentials.UserName.Password = "TestPassword";
string str = s1.GetData(1);
}
}
如果您分别使用:ClientCredentials.UserName.UserName和ClientCredentials.UserName.Password提供用户名和密码,那么客户端是否始终与基本身份验证通信?
这个问题来自这个问题:Basic Authentication appears to have no security header。我很困惑,为什么我在Authorization标头中看不到基本的身份验证凭据。
我在这里阅读了文档,但我没有找到答案:https://msdn.microsoft.com/en-us/library/system.servicemodel.description.clientcredentials.username(v=vs.110).aspx。